/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.everdras.blackPlague;

import java.util.List;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;

/**
 *
 * @author Josh
 */
public class PlagueSpreadListener extends EntityListener {
    private PlagueThread plague;
    
    public PlagueSpreadListener(PlagueThread plague) {
        this.plague = plague;
    }
    
    @Override
    public void onEntityDeath(EntityDeathEvent event) {
        if(plague == null || !plague.isAlive()) { 
            return;
        }
        
        Entity dead = event.getEntity();
        
        if(!(dead instanceof Zombie)) {
            return;
        }
        
        Zombie spreader = (Zombie) dead;
        
        double[] args = new double[3];
        List<Entity> nearbyEntities = spreader.getNearbyEntities(args[0], args[1], args[2]);
        
        for(Entity e : nearbyEntities) {
            if(e instanceof Player) {
                plague.addInfected((Player) e);
            }
        } //end for of nearby Entities 
        
    }
    
    public void setPlagueThread(PlagueThread pt) {
        plague = pt;
    }
    
    public PlagueThread getPlagueThread() {
        return plague;
    }

    
}